Skip to main content

Using the SDK

Using the SDK is simple and takes some inspiration from the AWS SDK.

For authentication examples see the Authentication guide this guide will use StaticAuthProvider for simplicity.

Initializing the SDK

import { WLLRewardsSdk, StaticAuthProvider } from '@wll-sdk/api';

const wllSdk = new WLLRewardsSdk({
apiKey: '<your-api-key>',
authProvider: new StaticAuthProvider({
token: '<your-token>',
}),
baseUrl: 'https://api.staging.rewards.wlloyalty.net/v1',
});

Using the SDK

The SDK mostly follows the paths of endpoints shown in the API Docs

For example: /rewards would become wllSdk.reward.list

Here is a minimal example of initializing the SDK and fetching a list of rewards.

import { WLLRewardsSdk, StaticAuthProvider } from '@wll-sdk/api';

const wllSdk = new WLLRewardsSdk({
apiKey: '<your-api-key>',
authProvider: new StaticAuthProvider({
token: '<your-token>',
}),
baseUrl: 'https://api.staging.rewards.wlloyalty.net/v1',
});

const rewards = await wllSdk.reward.list();

console.log(rewards); // Output: { data: [...your rewards] }

Different endpoints will have different requirements, such as query params, body or headers. Where necessary these should be typed.

Reference

PropertytypeRequired?
apiKeystringY
authProviderAuthProviderY
baseUrlstringY

Limitations

Currently responses from the SDK are not typed or validated. Please ensure you do appropriate validation if this is needed for your use case.